package com.ptswitch.material.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ptswitch.material.model.common.HTree;

public interface HTreeMapper {
    @Select("select * from htree_find_ancs(#{id})")
    List<HTree> findAncestors(@Param("id") String id);

    @Select("select * from htree_find_descs(#{id}) ")
    List<HTree> findDescendants(@Param("id") String pid);

    @Select("select * from htree_htree where id in ("//
            + " select pid from htree_htree where id = #{id} )")
    List<HTree> findParents(@Param("id") String id);//允许多个父亲

    @Select("select * from htree_tree where pid = #{pid}")
    List<HTree> findChildren(@Param("pid") String pid);

    @Insert("insert into htree_tree(id,pid) values(#{id},#{pid})")
    void insert(@Param("id") String id, @Param("pid") String pid);

    @Delete("delete from htree_tree where id in (select id from htree_find_descs(#{id})")
    //"delete from htree_tree where id = :id"
    void delete(@Param("id") String id, boolean deleteAllDescs);

    @Update("update htree_tree set pid = :pid where id = #{id}")
    void move(@Param("id") String id, @Param("pid") String npid);
}
